package com.ray.test.mock;

import com.ray.test.proxy.Handler;

import java.lang.reflect.Method;
import java.lang.reflect.Parameter;

/**
 * @author bo shen
 * @Description: 接口实例话
 * @Class: InterfaceDataMock
 * @Package com.ray.test.mock
 * @date 2019/12/13 10:21
 * @company <p>杭州传化陆鲸科技有限公司</p>
 * @updateRecord time(修改时间)  author(修改人)   desc(修改内容)
 */
public class InterfaceDataMock implements DataMock {
    @Override
    public Object dataMocker(Class<?> clazz, Method method, Parameter parameter) {
        Object configValue = MockConfig.getResultMap().get(clazz);
        if (configValue != null) {
            return configValue;
        }
        if (clazz.isInterface()) {
            return java.lang.reflect.Proxy.newProxyInstance(this.getClass().getClassLoader(), new Class<?>[]{clazz}, new Handler(clazz));
        }
        return null;
    }
}
